public class SymmetricTree {//leecode 101
    public boolean isSymmetric(TreeNode root) {// 核心:判断左树的左和右树的右是否相同!!!
        if(root==null) return true;
        if((root.left==null&&root.right!=null)||(root.left!=null&&root.right==null))
        {
            return false;
        }
        if(root.left==null&&root.right==null){
            return true;
        }

        return func(root.left,root.right);


    }

    public boolean func(TreeNode left,TreeNode right){
        if(left==null&&right==null){
            return true;
        }
        if(left==null&&right!=null||right==null&&left!=null){
            return false;
        }
        if(right.val==left.val){
            return func(left.left,right.right)&&func(left.right,right.left);
        }
        return false;
    }
}
